<?php
require 'inc_security.php';
$catBase = new Category;
$arrCat = $catBase->list_categories(0,'cat_active = 1 AND cat_type !="news"','cat_id,cat_name,cat_type','cat_id ASC');
foreach($arrCat as $i=>$cat){
    $tt = '';
    for($j=0;$j<$cat["level"];$j++) $tt .= '|--';
    $pro_cat_id[$cat["cat_id"]] = $tt . $cat["cat_name"];
}
$pro_factory = AdminController::GetDropdownData('factory','fac_id','fac_name');
$list = new dataGrid('pro_id',30);
$list->add('','Ảnh','string',0,0);
$list->add('pro_name','Tên sản phẩm','string',1,1, 'width="120px"');
$list->add('pro_cat_id','Danh mục','array',1,1);
$list->add('pro_factory','Hãng sản xuất','array',1,1);
$list->add('pro_price','Giá','interger',0,1);
$list->add('','Hot');
$list->add('','New');
$list->add('','Active','string');
$list->add('','Edit','edit');
$list->add('','Delete','delete');
$list->addSearch('Loại sản phẩm','pro_cat_type','array',$global_product_category_type);
$db_count = new db_count('SELECT count(*) as count 
                            FROM '.$bg_table.'
                            WHERE 1 '.$list->sqlSearch().'
                            ');
$total = $db_count->total;unset($db_count);

$db_listing = new db_query('SELECT * 
                            FROM '.$bg_table.'
                            WHERE 1 '.$list->sqlSearch().'
                            ORDER BY '.$list->sqlSort().' pro_id DESC, pro_date DESC
                            '.$list->limit($total));
$total_row = mysql_num_rows($db_listing->result);
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi" lang="vi" xmlns:og="http://ogp.me/ns#" xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?=$load_header?>
</head>
<body>
<div class="module_header bold fix"><?=$module_name?></div>
<div id="wrapper">
    <?=$list->showHeader($total_row)?>
    <?php
    $i = 0; 
    ?>
    <?php while($row = mysql_fetch_assoc($db_listing->result)){
        $i++;
    ?>
        <?=$list->start_tr($i,$row[$id_field])?>
        <td class="center">
            <div class="img_thumb">
                <img src="<?=$bg_filepath?><?=$row[$thumb_field]?>" alt="Không có ảnh"/>
            </div>
            <?=form_upload($thumb_field.$row[$id_field],'','onchage="check_edit(\'record_'.$i.'\')"')?>
        </td>
        <td>
            <div class="row">
                <div class="span1">Name</div>
                <div class="span3"><?=form_input($name_field.$row[$id_field],$row[$name_field],'class="span3" onkeyup="check_edit(\'record_'.$i.'\')"')?></div>
            </div>
            <div class="row">
                <div class="span1">Date</div>
                <div class="span3"><?=date('d/m/Y H:i',$row['pro_date'])?></div>
            </div>
        </td>
        <td><?=form_dropdown('pro_cat_id'.$row[$id_field],$pro_cat_id,$row['pro_cat_id'],'onchange="check_edit(\'record_'.$i.'\')"')?></td>
        <td><?=form_dropdown('pro_factory'.$row[$id_field],$pro_factory,$row['pro_factory'],'onchange="check_edit(\'record_'.$i.'\')"')?></td>
        <td><?=format_price($row['pro_price'])?></td>
        <?=$list->showCheckbox('pro_hot',$row['pro_hot'],$row[$id_field])?>
        <?=$list->showCheckbox('pro_new',$row['pro_new'],$row[$id_field])?>
        <?=$list->showCheckbox('pro_active',$row['pro_active'],$row[$id_field])?>
        <?=$list->showEdit($row[$id_field])?>
        <?=$list->showDelete($row[$id_field])?>
        <?=$list->end_tr()?>
    <?}?>
    <?=$list->showFooter()?>
</div>
</body>
</html>